﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Portal.Utility;
using Portal.Xml.Utility;

namespace Portal.Cms.Model
{
    public class CmsDataCls
    {
        public string DataId;
        public string WorkflowDefId;
        public string DataAlias;
        public string GroupDataAlias;
        public string GroupDataName;
        public string frkGroupDataId;
        public string ParentDataId;
        public string Subject;
        public string OtherSubject;
        public string Description;
        public string Body;
        public string Source;
        public DateTime EntryDate;
        public DateTime UpdatedDate;
        public string Avatar;
        public string Url;
        public string Target;
        public string EntryBy;
        public string AssetCode;
        public string DataLanguage;
        public string DataType;

        public string frkDocTypeId;
        public string DocTypeName;

        public string frkDocReleaseFromId;
        public string DocReleaseFromName;

        public string frkDocSignerId;
        public string DocSignerName;

        public string frkDocFieldId;
        public string DocFieldName;

        public string frkDocYearRangeId;
        public string DocYearRangeName;

        public string EffectedDate;
        public string EndEffectedDate;
        public string ExpiredDate;
        public string SignDate;
        public string ReleaseDate;
        public string ReplaceDoc;
        public string ModifyDoc;
        public string DocStatus;
        public string AttachDoc = "";
        public string VoteType = "";

        public int IsPublic;
        public int SortIndex;
        public int TotalPreview = 0;
        public int TotalDownload=0;
        public int IsNew = 0;
        public int AttachedSearchable = 0;
        public int TotalVote = 0;
        public string VoteDataText = "";
        public string SubDataType = "";
        public string RelationTypeName = "";
        public int NeedApproved = 0;

        //cho bao.....
        public string CategoryIds="";
        public string HotCategoryIds="";

        public string MapCategoryIds = "";
        public string MapHotCategoryIds = "";


        public string NewsTypeId="";
        public string ImageLevelId="";
        public string EventId="";
        public int ExpImageCount=0;
        public string ExpImageLevelId="";
        public string NewsLevelId="";
        public int IsFocus=0;
        public int IsShowAuthor=0;
        public int IsAdv=0;
        public string Keyword="";
        public string SurveyCode="";
        public string Note = "";
        public string Categories = "";
        public string ArchiveDocFile = "";
        public string ArchiveXmlFile = "";

        public string frkGroupDataFolderId = "";//temp
        public string UploadFile = "";//temp

        public int RequiredData = 0;

        public DateTime SchedulePublishingDate;

        public string JobTitle;

        public string GetAvatarFilePath(string SiteId, string DataPathRoot)
        {
            //Environments.DataPathRoot(SiteId)
            return DataPathRoot + "\\Cms\\" + AssetCode + "\\" + frkGroupDataId + "\\" + Avatar;
        }

        public string GetAvatarUrl(string SiteId,string HttpDataRoot)
        {
            //Environments.HttpDataRoot(SiteId)
            return HttpDataRoot + "/Cms/" + AssetCode + "/" + frkGroupDataId + "/" + Avatar;
        }

        public string GetAvatarCropUrl(string HttpDataRoot,string SiteId)
        {
            //Environments.HttpDataRoot(SiteId)
            return HttpDataRoot + "/Cms/" + AssetCode + "/" + frkGroupDataId + "/Crop/" + Avatar;
        }

        public string GetAvatarThumbUrl(string SiteId, string HttpDataRoot)
        {
            //Environments.HttpDataRoot(SiteId)
            return  HttpDataRoot+ "/Cms/" + AssetCode + "/" + frkGroupDataId + "/Thumb/" + Avatar;
        }

        //public string GetAttachDocUrlWithRoot(string SiteId, string HttpDataRoot)
        //{
        //    //Environments.HttpDataRoot(SiteId)
        //    return HttpDataRoot + "/DocumentArchives/" + AssetCode + "/ArchiveDoc/Root/" + frkGroupDataId + "/" + AttachDoc;
        //}


        public string GetAttachDocUrl(string SiteId, string HttpDataRoot)
        {
            //Environments.HttpDataRoot(SiteId) 
            return HttpDataRoot+ "/DocumentArchives/" + AssetCode + "/ArchiveDoc/Archive/" + AttachDoc;
        }

        public string GetAttachDocFile(string SiteId,string DataPathRoot)
        {
            //Environments.DataPathRoot(SiteId) 
            string DocFile = DataPathRoot+ "\\DocumentArchives\\" + AssetCode + "\\ArchiveDoc\\Archive\\" + AttachDoc;
            return DocFile;
        }

        //public string GetAttachDocFileWithDataPathRoot(string DataPathRoot)
        //{
        //    string DocFile = DataPathRoot + "\\DocumentArchives\\" + AssetCode + "\\ArchiveDoc\\root\\" + frkGroupDataId + "\\" + AttachDoc;
        //    return DocFile;
        //}


        //public string GetFlashFileWithDataPathRoot(string DataPathRoot)
        //{
        //    string DocFile = "";
        //    string FlashDir= DataPathRoot + "\\DocumentArchives\\" + AssetCode + "\\ArchiveDoc\\root\\" + frkGroupDataId + "\\flash";
        //    System.IO.Directory.CreateDirectory(FlashDir);
        //    if (!string.IsNullOrEmpty(AttachDoc))
        //    {
        //        string Ext = new System.IO.FileInfo(AttachDoc).Extension;
        //        string FlashFile = AttachDoc.Replace(Ext, ".swf");
        //        DocFile = FlashDir + "\\" + FlashFile;
        //    }
        //    return DocFile;
        //}




        //public string GetFlashFileHttp(string SiteId, string DataPathRoot)
        //{
        //    string DocFile = "";
        //    //string DataPathRoot = Environments.HttpDataRoot(SiteId);
        //    string FlashDir = DataPathRoot + "/DocumentArchives/" + AssetCode + "/ArchiveDoc/root/" + frkGroupDataId + "/flash";
        //    if (!string.IsNullOrEmpty(AttachDoc))
        //    {
        //        string Ext = new System.IO.FileInfo(AttachDoc).Extension;
        //        string FlashFile = AttachDoc.Replace(Ext, ".swf");
        //        DocFile = FlashDir + "/" + FlashFile;
        //    }
        //    return DocFile;
        //}


        //public static string GetAttachDocFileWithDataPathRoot(string AssetCode, string GroupDataId, string DataPathRoot, string AttachDoc)
        //{
        //    string DocFile = DataPathRoot + "\\DocumentArchives\\" + AssetCode + "\\ArchiveDoc\\root\\" + GroupDataId + "\\" + AttachDoc;
        //    return DocFile;
        //}

        //public string GetAttachDocFileXmlWithDataPathRoot(string DataPathRoot)
        //{
        //    string DocFile = DataPathRoot + "\\DocumentArchives\\" + AssetCode + "\\ArchiveDoc\\root\\" + frkGroupDataId + "\\" + AttachDoc+".xml";
        //    return DocFile;
        //}

        public string GetAttachDocFileXml(string SiteId, string DataPathRoot)
        {
            string DocFile = GetAttachDocFile(DataPathRoot,SiteId);
            string XmlFile = new System.IO.FileInfo(DocFile).FullName+".xml";
            return XmlFile;
        }

        public string GetSmallAvatarUrl(string SiteId, string HttpDataRoot)
        {
            //Environments.HttpDataRoot(SiteId) 
            return HttpDataRoot+ "/Cms/" + AssetCode + "/" + frkGroupDataId + "/thumb/" + Avatar;
        }
        public bool HasImage(string SiteId, string DataPathRoot)
        {
            //Environments.DataPathRoot(SiteId) 
            string ImageFile=DataPathRoot+ "\\Cms\\" + AssetCode + "\\" + frkGroupDataId + "\\" + Avatar;
            return System.IO.File.Exists(ImageFile);
        }


        public string GetXmlForCatche()
        {
            DataSet dsXml = new DataSet();
            dsXml.Tables.Add("Info");
            dsXml.Tables["Info"].Columns.Add("DataId");

            dsXml.Tables["Info"].Columns.Add("frkGroupDataId");
            dsXml.Tables["Info"].Columns.Add("ParentDataId");
            dsXml.Tables["Info"].Columns.Add("DataAlias");
            dsXml.Tables["Info"].Columns.Add("Subject");
            dsXml.Tables["Info"].Columns.Add("Description");
            dsXml.Tables["Info"].Columns.Add("Body");
            dsXml.Tables["Info"].Columns.Add("Source");
            dsXml.Tables["Info"].Columns.Add("Url");
            dsXml.Tables["Info"].Columns.Add("Target");
            dsXml.Tables["Info"].Columns.Add("Avatar");
            dsXml.Tables["Info"].Columns.Add("AttachDoc");
            dsXml.Tables["Info"].Columns.Add("EntryDate");
            dsXml.Tables["Info"].Columns.Add("UpdatedDate");
            dsXml.Tables["Info"].Columns.Add("AssetCode");
            dsXml.Tables["Info"].Columns.Add("DataLanguage");
            dsXml.Tables["Info"].Columns.Add("SortIndex");

            dsXml.Tables["Info"].Columns.Add("frkDocTypeId");
            dsXml.Tables["Info"].Columns.Add("DocTypeName");

            dsXml.Tables["Info"].Columns.Add("frkDocFieldId");
            dsXml.Tables["Info"].Columns.Add("DocFieldName");

            dsXml.Tables["Info"].Columns.Add("frkDocReleaseFromId");
            dsXml.Tables["Info"].Columns.Add("DocReleaseFromName");

            dsXml.Tables["Info"].Columns.Add("frkDocSignerId");
            dsXml.Tables["Info"].Columns.Add("DocSignerName");

            dsXml.Tables["Info"].Columns.Add("frkDocYearRangeId");
            dsXml.Tables["Info"].Columns.Add("DocYearRangeName");

            dsXml.Tables["Info"].Columns.Add("DocStatus");

            dsXml.Tables["Info"].Columns.Add("SignDate");
            dsXml.Tables["Info"].Columns.Add("SearchSignDate");


            dsXml.Tables["Info"].Columns.Add("ReleaseDate");
            dsXml.Tables["Info"].Columns.Add("SearchReleaseDate");

            dsXml.Tables["Info"].Columns.Add("EffectedDate");
            dsXml.Tables["Info"].Columns.Add("SearchEffectedDate");

            dsXml.Tables["Info"].Columns.Add("EndEffectedDate");
            dsXml.Tables["Info"].Columns.Add("EndSearchEffectedDate");

            dsXml.Tables["Info"].Columns.Add("ReplaceDoc");
            dsXml.Tables["Info"].Columns.Add("ModifyDoc");
            dsXml.Tables["Info"].Columns.Add("VoteType");
            dsXml.Tables["Info"].Columns.Add("IsPublic");
            dsXml.Tables["Info"].Columns.Add("IsNew");
            dsXml.Tables["Info"].Columns.Add("AttachedSearchable");
            dsXml.Tables["Info"].Columns.Add("TotalVote");
            dsXml.Tables["Info"].Columns.Add("VoteDataText");

            dsXml.Tables["Info"].Columns.Add("DataSort");
            dsXml.Tables["Info"].Columns.Add("NeedApproved");

            dsXml.Tables["Info"].Columns.Add("frkGroupDataFolderId");
            
            string[] AllItems = DataAlias.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
            string DataSort = "";
            for (int iIndex = 0; iIndex < AllItems.Length; iIndex++)
            {
                DataSort = DataSort + AllItems[iIndex].PadLeft(25, '0');
                //if (iIndex < AllItems.Length - 1)
                //{
                //    DataSort = DataSort + "/";
                //}
            }
            int Max=10-AllItems.Length;
            if (Max > 0)
            {
                for (int iIndex = 0; iIndex < Max; iIndex++)
                {
                    DataSort = "0".PadLeft(25, '0') +  DataSort;
                }
            }


            DataRow dr = dsXml.Tables["Info"].NewRow();
            dr["DataId"] = DataId;
            dr["frkGroupDataId"] = "$" + frkGroupDataId + "$";
            dr["ParentDataId"] = "$" + ParentDataId + "$";
            dr["DataAlias"] = DataAlias;
            dr["Subject"] = Subject;
            dr["Description"] = Description;
            dr["Body"] = Body;
            dr["Source"] = Source;
            dr["Url"] = Url;
            dr["Target"] = Target;
            dr["Avatar"] = Avatar;
            dr["AttachDoc"] = AttachDoc;
            dr["EntryDate"] = EntryDate;
            dr["UpdatedDate"] = UpdatedDate;
            dr["AssetCode"] = "$" + AssetCode + "$";
            dr["DataLanguage"] = "$" + DataLanguage + "$";
            dr["SortIndex"] = SortIndex;
            dr["frkDocTypeId"] = "$" + frkDocTypeId + "$";
            dr["DocTypeName"] = DocTypeName;

            dr["frkDocFieldId"] = "$" + frkDocFieldId + "$";
            dr["DocFieldName"] = DocFieldName;

            dr["frkDocReleaseFromId"] = "$" + frkDocReleaseFromId + "$";
            dr["DocReleaseFromName"] = DocReleaseFromName;

            dr["frkDocSignerId"] = "$" + frkDocSignerId + "$";
            dr["DocSignerName"] = DocSignerName;

            dr["frkDocYearRangeId"] = "$" + frkDocYearRangeId + "$";
            dr["DocYearRangeName"] = DocYearRangeName;

            dr["DocStatus"] = DocStatus;
            dr["SignDate"] = SignDate;
            try
            {
                DateTime DSignDate = FunctionUtilities.VNDateToDate(SignDate);
                dr["SearchSignDate"] = DSignDate.ToString("dd/MM/yyyy");  //ProcessDate(DSignDate.Month) + " " + DSignDate.Month.ToString().PadLeft(2, '0') + ", " + DSignDate.Year;
            }
            catch { }

            dr["ReleaseDate"] = ReleaseDate;
            try
            {
                DateTime DReleaseDate = FunctionUtilities.VNDateToDate(ReleaseDate);
                dr["SearchReleaseDate"] = DReleaseDate.ToString("dd/MM/yyyy");// ProcessDate(DReleaseDate.Month) + " " + DReleaseDate.Month.ToString().PadLeft(2, '0') + ", " + DReleaseDate.Year;
            }
            catch { }

            dr["EffectedDate"] = EffectedDate;
            try
            {
                DateTime DSearchEffectedDate = FunctionUtilities.VNDateToDate(EffectedDate);
                dr["SearchEffectedDate"] = DSearchEffectedDate.ToString("dd/MM/yyyy");// ProcessDate(DSearchEffectedDate.Month) + " " + DSearchEffectedDate.Month.ToString().PadLeft(2, '0') + ", " + DSearchEffectedDate.Year;
            }
            catch { }

            dr["EndEffectedDate"] = EndEffectedDate;
            try
            {
                DateTime DEndSearchEffectedDate = FunctionUtilities.VNDateToDate(EndEffectedDate);
                dr["EndSearchEffectedDate"] = DEndSearchEffectedDate.ToString("dd/MM/yyyy");// ProcessDate(DSearchEffectedDate.Month) + " " + DSearchEffectedDate.Month.ToString().PadLeft(2, '0') + ", " + DSearchEffectedDate.Year;
            }
            catch { }

            dr["ReplaceDoc"] = ReplaceDoc;
            dr["ModifyDoc"] = ModifyDoc;
            dr["VoteType"] = VoteType;
            dr["IsPublic"] = IsPublic;
            dr["IsNew"] = IsNew;
            dr["AttachedSearchable"] = AttachedSearchable;
            dr["AttachedSearchable"] = TotalVote;
            dr["VoteDataText"] = VoteDataText;
            dr["DataSort"] = DataSort;
            dr["NeedApproved"] = NeedApproved;

            dr["frkGroupDataFolderId"] = "$" + frkGroupDataFolderId + "$";

            dsXml.Tables["Info"].Rows.Add(dr);
            return dsXml.GetXml();
        }
    }

    public class CmsDataParser
    {
        public static CmsDataCls CreateInstance()
        {
            //tao 1 class trang....
            CmsDataCls oCmsDataCls = new CmsDataCls();
            return oCmsDataCls;
        }

        public static CmsDataCls ParseFromXml(string XmlData)
        {
            DataSet ds = XmlUtility.GetDataSetFromXml(XmlData);
            CmsDataCls oCmsDataCls = ParseFromDataRow(ds.Tables[0].Rows[0]);
            return oCmsDataCls;
        }


        public static CmsDataCls ParseFromDataRow(DataRow dr)
        {
            CmsDataCls oCmsDataCls = new CmsDataCls();
            oCmsDataCls.DataId = XmlUtility.GetString(dr, "DataId", true);
            oCmsDataCls.DataAlias = XmlUtility.GetString(dr, "DataAlias", true);
            oCmsDataCls.AssetCode = XmlUtility.GetString(dr, "AssetCode", true);
            oCmsDataCls.GroupDataAlias = XmlUtility.GetString(dr, "GroupDataAlias", true);
            oCmsDataCls.GroupDataName = XmlUtility.GetString(dr, "GroupDataName", true);
            oCmsDataCls.Subject = XmlUtility.GetString(dr, "Subject", true);
            oCmsDataCls.OtherSubject = XmlUtility.GetString(dr, "OtherSubject", true);
            oCmsDataCls.Description = XmlUtility.GetString(dr, "Description", true);
            oCmsDataCls.Body = XmlUtility.GetString(dr, "Body", true);
            oCmsDataCls.Source = XmlUtility.GetString(dr, "Source", true);
            oCmsDataCls.EntryDate = XmlUtility.GetDate(dr, "EntryDate", true);
            oCmsDataCls.UpdatedDate = XmlUtility.GetDate(dr, "UpdatedDate", true);
            oCmsDataCls.SchedulePublishingDate = XmlUtility.GetDate(dr, "SchedulePublishingDate", true);

            oCmsDataCls.Avatar = XmlUtility.GetString(dr, "Avatar", true);
            oCmsDataCls.Url = XmlUtility.GetString(dr, "Url", true);
            oCmsDataCls.Target = XmlUtility.GetString(dr, "Target", true);
            oCmsDataCls.EntryBy = XmlUtility.GetString(dr, "EntryBy", true);
            oCmsDataCls.IsPublic = XmlUtility.GetInt(dr, "IsPublic", true);
            oCmsDataCls.DocStatus = XmlUtility.GetString(dr, "DocStatus", true);
            oCmsDataCls.SortIndex = XmlUtility.GetInt(dr, "SortIndex", true);
            oCmsDataCls.frkGroupDataId = XmlUtility.GetString(dr, "frkGroupDataId", true);
            oCmsDataCls.AssetCode = XmlUtility.GetString(dr, "AssetCode", true);
            oCmsDataCls.DataType = XmlUtility.GetString(dr, "DataType", true);
            oCmsDataCls.AttachDoc = XmlUtility.GetString(dr, "AttachDoc", true);
            oCmsDataCls.VoteType = XmlUtility.GetString(dr, "VoteType", true);
            
            oCmsDataCls.frkDocTypeId = XmlUtility.GetString(dr, "frkDocTypeId", true);
            oCmsDataCls.DocTypeName = XmlUtility.GetString(dr, "DocTypeName", true);

            oCmsDataCls.frkDocFieldId = XmlUtility.GetString(dr, "frkDocFieldId", true);
            oCmsDataCls.DocFieldName = XmlUtility.GetString(dr, "DocFieldName", true);

            oCmsDataCls.frkDocYearRangeId = XmlUtility.GetString(dr, "frkDocYearRangeId", true);
            oCmsDataCls.DocYearRangeName = XmlUtility.GetString(dr, "DocYearRangeName", true);
            
         
            oCmsDataCls.frkDocReleaseFromId = XmlUtility.GetString(dr, "frkDocReleaseFromId", true);
            oCmsDataCls.DocReleaseFromName = XmlUtility.GetString(dr, "DocReleaseFromName", true);
            oCmsDataCls.frkDocSignerId = XmlUtility.GetString(dr, "frkDocSignerId", true);
            oCmsDataCls.DocSignerName = XmlUtility.GetString(dr, "DocSignerName", true);

            oCmsDataCls.VoteType = XmlUtility.GetString(dr, "VoteType", true);

            oCmsDataCls.WorkflowDefId = XmlUtility.GetString(dr, "WorkflowDefId", true);
            

            oCmsDataCls.ParentDataId = XmlUtility.GetString(dr, "ParentDataId", true);
            oCmsDataCls.DataLanguage = XmlUtility.GetString(dr, "DataLanguage", true);
            oCmsDataCls.SubDataType = XmlUtility.GetString(dr, "SubDataType", true);
            oCmsDataCls.RelationTypeName = XmlUtility.GetString(dr, "RelationTypeName", true);
            try
            {
                oCmsDataCls.EffectedDate = XmlUtility.GetDate(dr, "EffectedDate", true).ToString("dd/MM/yyyy");
                if (oCmsDataCls.EffectedDate.Equals("01/01/0001"))
                {
                    oCmsDataCls.EffectedDate = "";
                }
            }
            catch { }

            try
            {
                oCmsDataCls.DocSignerName = XmlUtility.GetString(dr, "DocSignerName", true);
            }
            catch { }

            try
            {
                oCmsDataCls.JobTitle = XmlUtility.GetString(dr, "JobTitle", true);
            }
            catch { }
            

            try
            {
                oCmsDataCls.DocReleaseFromName = XmlUtility.GetString(dr, "DocReleaseFromName", true);
            }
            catch { }
            try
            {
                oCmsDataCls.EndEffectedDate = XmlUtility.GetDate(dr, "EndEffectedDate", true).ToString("dd/MM/yyyy");
                if (oCmsDataCls.EndEffectedDate.Equals("01/01/0001"))
                {
                    oCmsDataCls.EndEffectedDate = "";
                }
            }
            catch { }

            try
            {
                oCmsDataCls.SignDate = XmlUtility.GetDate(dr, "SignDate", true).ToString("dd/MM/yyyy");
                if (oCmsDataCls.SignDate.Equals("01/01/0001"))
                {
                    oCmsDataCls.SignDate = "";
                }
            }
            catch { }
            try
            {
                oCmsDataCls.ReleaseDate = XmlUtility.GetDate(dr, "ReleaseDate", true).ToString("dd/MM/yyyy");
                if (oCmsDataCls.ReleaseDate.Equals("01/01/0001"))
                {
                    oCmsDataCls.ReleaseDate = "";
                }
            }
            catch { }
            oCmsDataCls.ReplaceDoc = XmlUtility.GetString(dr, "ReplaceDoc", true);
            oCmsDataCls.ModifyDoc = XmlUtility.GetString(dr, "ModifyDoc", true);
            oCmsDataCls.DocStatus = XmlUtility.GetString(dr, "DocStatus", true);

            oCmsDataCls.TotalPreview = XmlUtility.GetInt(dr, "TotalPreview", true);
            oCmsDataCls.TotalDownload = XmlUtility.GetInt(dr, "TotalDownload", true);
            oCmsDataCls.IsNew = XmlUtility.GetInt(dr, "IsNew", true);
            oCmsDataCls.AttachedSearchable = XmlUtility.GetInt(dr, "AttachedSearchable", true);
            oCmsDataCls.TotalVote = XmlUtility.GetInt(dr, "TotalVoteChecked", true);
            oCmsDataCls.VoteDataText = XmlUtility.GetString(dr, "VoteDataText", true);
            oCmsDataCls.SubDataType = XmlUtility.GetString(dr, "SubDataType", true);
            oCmsDataCls.NeedApproved = XmlUtility.GetInt(dr, "NeedApproved", true);
            oCmsDataCls.frkGroupDataFolderId = XmlUtility.GetString(dr, "frkGroupDataFolderId", true);

            //danh cho báo
            oCmsDataCls.CategoryIds = XmlUtility.GetString(dr, "CategoryIds", true);
            oCmsDataCls.HotCategoryIds = XmlUtility.GetString(dr, "HotCategoryIds", true);
            oCmsDataCls.MapCategoryIds = XmlUtility.GetString(dr, "MapCategoryIds", true);
            oCmsDataCls.MapHotCategoryIds = XmlUtility.GetString(dr, "MapHotCategoryIds", true);

            oCmsDataCls.NewsTypeId = XmlUtility.GetString(dr, "NewsTypeId", true);
            oCmsDataCls.ImageLevelId = XmlUtility.GetString(dr, "ImageLevelId", true);
            oCmsDataCls.EventId = XmlUtility.GetString(dr, "EventId", true);
            oCmsDataCls.ExpImageCount = XmlUtility.GetInt(dr, "ExpImageCount", true);
            oCmsDataCls.ExpImageLevelId = XmlUtility.GetString(dr, "ExpImageLevelId", true);
            oCmsDataCls.NewsLevelId = XmlUtility.GetString(dr, "NewsLevelId", true);
            oCmsDataCls.IsFocus = XmlUtility.GetInt(dr, "IsFocus", true);
            oCmsDataCls.IsShowAuthor = XmlUtility.GetInt(dr, "IsShowAuthor", true);
            oCmsDataCls.IsAdv = XmlUtility.GetInt(dr, "IsAdv", true);
            oCmsDataCls.Keyword = XmlUtility.GetString(dr, "Keyword", true);
            oCmsDataCls.SurveyCode = XmlUtility.GetString(dr, "SurveyCode", true);
            oCmsDataCls.Note = XmlUtility.GetString(dr, "Note", true);
            oCmsDataCls.EntryBy = XmlUtility.GetString(dr, "EntryBy", true);
            oCmsDataCls.Categories = XmlUtility.GetString(dr, "Categories", true);

            oCmsDataCls.ArchiveDocFile = XmlUtility.GetString(dr, "ArchiveDocFile", true);
            oCmsDataCls.ArchiveXmlFile = XmlUtility.GetString(dr, "ArchiveXmlFile", true);

            oCmsDataCls.RequiredData = XmlUtility.GetInt(dr, "RequiredData", true);

            try
            {
                oCmsDataCls.ExpiredDate = XmlUtility.GetDate(dr, "ExpiredDate", true).ToString("dd/MM/yyyy");
                if (oCmsDataCls.ExpiredDate.Equals("01/01/0001"))
                {
                    oCmsDataCls.ExpiredDate = "";
                }
            }
            catch { }
            return oCmsDataCls;
        }

        public  static CmsDataCls[] ParseFromDataTable(DataTable dtTable)
        {
            CmsDataCls[] CmsDatas = new CmsDataCls[dtTable.Rows.Count];
            for (int iIndex = 0; iIndex < dtTable.Rows.Count; iIndex++)
            {
                CmsDatas[iIndex] = ParseFromDataRow(dtTable.Rows[iIndex]);
            }

            return CmsDatas;
        }

        public static CmsDataCls[] ParseMultiRecordFromXml(string XmlData)
        {
            DataSet ds = XmlUtility.GetDataSetFromXml(XmlData);
            if (ds.Tables.Count == 0)
            {
                return new CmsDataCls[0];
            }
            CmsDataCls[] CmsDatas = new CmsDataCls[ds.Tables[0].Rows.Count];
            for (int iIndex = 0; iIndex < ds.Tables[0].Rows.Count; iIndex++)
            {
                CmsDatas[iIndex] = ParseFromDataRow(ds.Tables[0].Rows[iIndex]);
            }
            return CmsDatas;
        }
    }
}
